package com.hongxun.design.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.HashMap;
import java.util.List;

import com.hongxun.design.R;
import com.hongxun.design.bean.PhotoPassagewayItemBean;
import com.hongxun.design.ui.dragview.ImageTextItem;

/**
 * Created by zerdoor_pc on 2016/4/27.
 */
public class PhotoPassGridAdapter extends BaseAdapter {
    List<PhotoPassagewayItemBean> itemBeanList;
    Context context;
    boolean isdelect = false;

    public PhotoPassGridAdapter(List<PhotoPassagewayItemBean> itemBeanList, Context context) {
        this.itemBeanList = itemBeanList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return itemBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return itemBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ImageTextItem item;
        if (convertView == null) {
            item = new ImageTextItem(context);
        }else{
            item= (ImageTextItem) convertView;
        }
//            convertView = LayoutInflater.from(context).inflate(R.layout.gridview_item_photopass, null);
        PhotoPassagewayItemBean itemBean = itemBeanList.get(i);

//        ViewHolerHelper viewHolerHelper = new ViewHolerHelper(convertView);
//        item.setIcon(itemBean.getUrl());
//        item.setValue(itemBean.getValue(), View.GONE);
//        item.setName(itemBean.getName());
//        item.setIconTouch(itemBean.getUrlSeleck());
        item.setData(itemBean,View.GONE);
//        MyLog.L("进入grid" + itemBean.getName());

        return item;
    }

    public class ViewHolerHelper {
        private HashMap<Integer, View> mViews;
        View convertView;

        public ViewHolerHelper(View convertView) {
            mViews = new HashMap<Integer, View>();
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.gridview_item_home_head, null);
            }
            convertView.setTag(this);
            this.convertView = convertView;
        }

        public <T> T getView(Integer R_Id) {
            View view = null;
            if (!mViews.containsKey(R_Id)) {
                view = convertView.findViewById(R_Id);
                if (view != null) {
                    mViews.put(R_Id, view);
                }
            } else {
                view = mViews.get(R_Id);
            }
            return (T) view;
        }
    }

    abstract class MyClickListener implements View.OnClickListener {
        int position;

        MyClickListener(int position) {
            this.position = position;
        }

        @Override
        public void onClick(View view) {
            onMyClick(view, position);
        }

        public abstract void onMyClick(View view, int position);
    }
}
